package com.colllection;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;

public class HashsetTest_1 {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        HashSet hashset=new HashSet();
        hashset.add(new Employ("jack",19));
        hashset.add(new Employ("mack",29));
        hashset.add(new Employ("tom",24));
        hashset.add(new Employ("jack",19));
        Iterator iterator=hashset.iterator();
//while(iterator.hasNext()){
//    System.out.println(hashset);
//}
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }

    }
}

class Employ{
    private String name;
    private int age;

    public Employ(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Employ{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employ employ = (Employ) o;
        return age == employ.age && Objects.equals(name, employ.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
